package com.gitee.faster.webdav.common.constant;

import cn.hutool.core.io.FileUtil;
import com.gitee.faster.webdav.kernel.FasterWebDavServer;

/**
 * 通用常量类
 *
 * @author hongda.li
 */
public final class Constants {

    public static final String VERSION = "2024.10";

    public static final String BASE_DATA_PATH = FileUtil.getUserHomePath() + "/.faster-webdav-server";

    public static final String LOG_PATH = BASE_DATA_PATH + "/logs";

    public static final String LOG_SUFFIX = ".log";

    public static final String XML_CONTENT_TYPE = "application/xml";

    public static final String HTML_CONTENT_TYPE = "text/html";

    public static final String JSON_CONTENT_TYPE = "application/json";

    public static final String CONTENT_TYPE_SUFFIX = "; charset=";

    public static final String E_TAG_TEMPLATE = "%s-%s";

    public static final String SPLIT_COMMA_SPACE = ", ";

    public static final String INDEX_PATH = "/index.html";

    public static final String API_PATH = "/api/system";

    public static final String DASH_SYMBOL = " - ";

    public static final String LINE_START_SYMBOL = "============================================================";

    public static final String NAME_SPACE_MAPPER = "org.glassfish.jaxb.namespacePrefixMapper";

    public static final String DAV_PREFIX = "DAV:";

    public static final String D_PREFIX = "d";

    public static final String BYTES = "bytes";

    public static final String CONTENT_RANGE_TEMPLATE = "bytes %s-%s/%s";

    public static final String READ_MODE = "r";

    public static final String BASIC_PREFIX = "Basic ";

    public static final String BASIC_REALM_VALUE = "Basic realm=\"" + FasterWebDavServer.class.getSimpleName() + "\"";

    public static final String EQUALS = "=";

    private Constants() {
    }

    public static final class Config {

        public static final String CONFIG_JSON_NAME = BASE_DATA_PATH + "/config.json";

        public static final String KEY_STORAGE_LOCAL_PATH = "storage.local.path";

        public static final String KEY_STORAGE_ALI_PATH = "storage.ali.path";

        public static final String KEY_STORAGE_BAIDU_PATH = "storage.baidu.path";

        public static final String VALUE_STORAGE_PATH = "${user.home}/WebDav/";

        public static final String USER_HOME = "${user.home}";

        public static final String KEY_HOST = "webdav.host";

        public static final String LOCAL_HOST = "${localhost}";

        public static final String KEY_PORT = "webdav.port";

        public static final int VALUE_PORT = 10010;

        public static final String KEY_WRITE_BUFFER_SIZE = "buffer.size.write";

        public static final int VALUE_WRITE_BUFFER_SIZE = 1024 * 8;

        public static final String KEY_READ_BUFFER_SIZE = "buffer.size.read";

        public static final int VALUE_READ_BUFFER_SIZE = 1024 * 8;

        public static final String KEY_SEARCH_MAX_DEPTH = "search.depth.max";

        public static final int VALUE_SEARCH_MAX_DEPTH = 3;

        public static final String KEY_AUTHORIZATION = "authorization";

        public static final String KEY_LOGGER_LEVEL = "logger.level";

        public static final String KEY_ALI_ACCESS_TOKEN = "ali.access_token";

        private Config() {
        }
    }

    @SuppressWarnings("SpellCheckingInspection")
    public static final class Ali {
        /**
         * 阿里云盘域名
         */
        public static final String ALI_DOMAIN = "openapi.alipan.com";

        /**
         * 获取授权码接口
         */
        public static final String OAUTH_PATH = "/oauth/authorize";

        /**
         * 获取 access_token
         */
        public static final String ACCESS_TOKEN_PATH = "/oauth/access_token";

        /**
         * 创建应用时分配的 AppId
         * 默认应用为 FasterWebDav
         * 若需要自定义应用，则需要在阿里云盘开发者门户中创建自己的应用并替换此项值
         */
        public static final String CLIENT_ID = "e94c47b2486448099780e046f0887704";

        /**
         * 获取 Drive 信息
         */
        public static final String DRIVE_API = "/adrive/v1.0/user/getDriveInfo";

        /**
         * 文件列表搜索
         */
        public static final String SEARCH_API = "/adrive/v1.0/openFile/search";

        /**
         * 文件获取下载链接
         */
        public static final String DOWNLOAD_URL_API = "/adrive/v1.0/openFile/getDownloadUrl";

        private Ali() {
        }
    }
}
